<template>
  <div>
    <el-form
      ref="formBizExam"
      :model="formBizExam"
      label-width="75px"
      :size="defaultFormItemSize"
      label-position="right"
      @submit.native.prevent
    >
      <filter-box :item-width="350" @search="refreshFormBizExam(true)" @reset="onReset">
        <el-form-item label="姓名" prop="formFilter.userName">
          <el-input
            class="filter-item"
            v-model="formBizExam.formFilter.userName"
            :clearable="true"
            placeholder="姓名"
          />
        </el-form-item>
      </filter-box>
    </el-form>
    <table-box
      class="page-table"
      :data="formBizExam.SysUser.impl.dataList"
      :size="defaultFormItemSize"
      @sort-change="formBizExam.SysUser.impl.onSortChange"
      @refresh="refreshFormBizExam(true)"
      :seq-config="{
        startIndex: (formBizExam.SysUser.impl.currentPage - 1) * formBizExam.SysUser.impl.pageSize
      }"
    >
      <vxe-column title="序号" type="seq" width="50px" />
      <vxe-column title="试卷" field="paperName" />
      <vxe-column title="姓名" field="userName" />
      <vxe-column title="分数" field="score" />
      <vxe-column title="题数" field="subjectCount" />
      <vxe-column title="答对题数" field="correctCount" />
      <vxe-column title="创建时间">
        <template slot-scope="scope">
          <span>{{ formatDateByStatsType(scope.row.createTime, 'datetime') }}</span>
        </template>
      </vxe-column>
      <!-- <vxe-column title="创建时间">
        <template slot-scope="scope">
          <span>{{formatDateByStatsType(scope.row.createTime, 'day')}}</span>
        </template>
      </vxe-column>
      <vxe-column title="操作" fixed="right" width="230px">
        <template slot-scope="scope">
          <el-button class="btn-table-edit" type="text" :size="defaultFormItemSize" @click="onEditRow(scope.row)">
            查看
          </el-button>
        </template>
      </vxe-column>-->

      <el-row slot="pagination" type="flex" justify="end" style="margin-top: 16px">
        <el-pagination
          :total="formBizExam.SysUser.impl.totalCount"
          :current-page="formBizExam.SysUser.impl.currentPage"
          :page-size="formBizExam.SysUser.impl.pageSize"
          :page-sizes="[10, 20, 50, 100]"
          layout="total, prev, pager, next, sizes"
          @current-change="formBizExam.SysUser.impl.onCurrentPageChange"
          @size-change="formBizExam.SysUser.impl.onPageSizeChange"
        >
        </el-pagination>
      </el-row>
    </table-box>
  </div>
</template>

<script>
import { treeDataTranslate } from '@/utils';
/* eslint-disable-next-line */
import { DropdownWidget, TableWidget, UploadWidget, ChartWidget } from '@/utils/widget.js';
/* eslint-disable-next-line */
import { uploadMixin, statsDateRangeMixin, cachePageMixin, cachedPageChildMixin } from '@/core/mixins';
/* eslint-disable-next-line */
import { BizExamController, DictionaryController } from '@/api';
import editSubject from '@/views/biz/formEditBizSubject';

export default {
  name: 'formBizExam',
  props: {},
  mixins: [uploadMixin, statsDateRangeMixin, cachePageMixin],
  data() {
    return {
      deptIdPath: [],
      formBizExam: {
        formFilter: {
          examType: 3,
          userName: ''
        },
        formFilterCopy: {
          examType: 3,
          userName: ''
        },
        SysUser: {
          impl: new TableWidget(
            this.loadBizExamData,
            this.loadBizExamVerify,
            true,
            false,
            'createTime',
            1
          )
        },
        isInit: false
      }
    };
  },
  methods: {
    onReset() {
      this.$refs.formBizExam.resetFields();
      this.refreshFormBizExam(true);
    },
    onEditRow(row) {
      this.loadRowData(row)
        .then(rowData => {
          this.$dialog
            .show(
              '查看记录',
              editSubject,
              {
                area: '1200px'
              },
              {
                rowData: rowData
              }
            )
            .then(res => {
              this.refreshFormBizExam();
            })
            .catch(e => {});
        })
        .catch(e => {
          //
        });
    },
    loadRowData(row) {
      return new Promise((resolve, reject) => {
        let params = {
          examId: row.examId
        };

        BizExamController.findById(this, params)
          .then(res => {
            resolve(res.data);
          })
          .catch(e => {
            reject(e);
          });
      });
    },
    loadBizExamData(params) {
      params.examFilter = {
        examType: this.formBizExam.formFilterCopy.examType,
        userName: this.formBizExam.formFilterCopy.userName
      };
      return new Promise((resolve, reject) => {
        BizExamController.list(this, params)
          .then(res => {
            resolve({
              dataList: res.data.dataList,
              totalCount: res.data.totalCount
            });
          })
          .catch(e => {
            reject(e);
          });
      });
    },
    loadBizExamVerify() {
      this.formBizExam.formFilterCopy.examType = this.formBizExam.formFilter.examType;
      this.formBizExam.formFilterCopy.userName = this.formBizExam.formFilter.userName;
      return true;
    },
    refreshFormBizExam(reloadData = false) {
      // 重新获取数据组件的数据
      if (reloadData) {
        this.formBizExam.SysUser.impl.refreshTable(true, 1);
      } else {
        this.formBizExam.SysUser.impl.refreshTable();
      }
      this.formBizExam.isInit = true;
    },
    onResume() {
      this.refreshFormBizExam();
    },
    initFormData() {},
    formInit() {
      this.initFormData();
      this.refreshFormBizExam();
    }
  },
  created() {
    this.formInit();
  }
};
</script>
